package com.ruoyi.wx.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import com.ruoyi.wx.mapper.ALikesMapper;
import com.ruoyi.wx.domain.ALikes;
import com.ruoyi.wx.service.IALikesService;

/**
 * 点赞Service业务层处理
 * 
 * @author pan
 * @date 2022-11-07
 */
@Service
public class ALikesServiceImpl implements IALikesService 
{

    private static final String key = "cat:like:loadLikes";  // Redis中的key

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Autowired
    private ALikesMapper aLikesMapper;



    /**
     * 查询点赞
     * 
     * @param id 点赞主键
     * @return 点赞
     */
    @Override
    public ALikes selectALikesById(Long id)
    {
        return aLikesMapper.selectALikesById(id);
    }

    /**
     * 查询点赞列表
     * 
     * @param aLikes 点赞
     * @return 点赞
     */
    @Override
    public List<ALikes> selectALikesList(ALikes aLikes)
    {
        return aLikesMapper.selectALikesList(aLikes);
    }

    /**
     * 新增点赞
     * 
     * @param aLikes 点赞
     * @return 结果
     */
    @Override
    public int insertALikes(ALikes aLikes)
    {
        // 插入之前，删除Redis中的缓存【顺序可换】
        redisTemplate.delete(key);

        return aLikesMapper.insertALikes(aLikes);
    }

    /**
     * 修改点赞
     * 
     * @param aLikes 点赞
     * @return 结果
     */
    @Override
    public int updateALikes(ALikes aLikes)
    {
        return aLikesMapper.updateALikes(aLikes);
    }

    /**
     * 批量删除点赞
     * 
     * @param ids 需要删除的点赞主键
     * @return 结果
     */
    @Override
    public int deleteALikesByIds(Long[] ids)
    {
        return aLikesMapper.deleteALikesByIds(ids);
    }

    /**
     * 删除点赞信息
     * 
     * @param id 点赞主键
     * @return 结果
     */
    @Override
    public int deleteALikesById(Long id)
    {
        return aLikesMapper.deleteALikesById(id);
    }


    /**
     * 喜欢列表
     * @return
     */
    @Override
    public List<ALikes> getLikesList(){
        return aLikesMapper.getLikesList();
    }
}
